package com.atguigu.jdk;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 迭代器模式
 * @create: 2022-03-07 13:37
 **/
public class IteratorDemo {

    //同样实现了iterator()方法来获取迭代器Iterator,只不过具体是由LinkedList父类AbstractSequentialList来实现的
    private LinkedList linkedList;

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("jack");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
    }
}
